package com.test.main;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class ProxySerialization {

	public static void main(String[] args) {
		Person person = new Person("vishesh", 25);
		
		// writing to a file
		 try {
		 FileOutputStream fos = new FileOutputStream("tempdata.ser");
         ObjectOutputStream oos = new ObjectOutputStream(fos);
        
			oos.writeObject(person);
			 oos.close();
			 System.out.println("operation successful");
		} catch (IOException e) {
			e.printStackTrace();
		}
        
		 try{
			 FileInputStream fis = new FileInputStream("tempdata.ser");
	         ObjectInputStream ois = new ObjectInputStream(fis);
	        Person ted = (Person) ois.readObject();
	         ois.close();
	         // Clean up the file
	         new File("tempdata.ser").delete();
	         System.out.println("Ther person is  : " + person);
		 }catch (IOException e) {
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

	}

}
